//
//  LGTRWZImageTextStepCell.swift
//  KJLGT
//
//  Created by jenkin on 2019/8/24.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTRWZPostDetailImageTextStepCell: UITableViewCell {
    
    var bottomClickBlock:ClickIndexBlock?
    var titleLabel:UILabel?
    var stepLabel:UILabel?
    var typeLabel:UILabel?
    var checkImageView:UIImageView?
    var descLabel:UILabel?
    private var _model:Dictionary<String, Any>?
    var path:IndexPath?
    var copyBtn:UIButton?
    var stepCellClickBlock:ClickStepPathBlock?
    var descArray:Array<String> = ["验证图", "上传说明图", "上传二维码"]
    var model:Dictionary<String, Any>{
        get{
            return _model ?? Dictionary.init()
        }set{
            _model = newValue
            self.setData()
        }
    }
    
    func setData(){
        self.titleLabel?.text = self.model["stepText"] as? String ?? ""
        let selectInfo:Dictionary<String, Any> = self.model["selectInfo"] as? Dictionary<String, Any> ?? [:]
        let url:String = selectInfo["url"] as? String ?? ""
        self.checkImageView?.sd_setImage(with: URL.init(string: url), completed: nil)
        
        let type:Int = self.model["type"] as? Int ?? 0
        self.descLabel?.isHidden = false
        if type == 2{
            self.descLabel?.isHidden = true
        }
        
        if type <= self.descArray.count - 1{
            self.descLabel?.text = self.descArray[type]
        }
        
        self.stepLabel?.text = "\((self.path?.row ?? 1))"
        //var type:Int = 0  //0上传验证图  1上传说明图 2上传二维码
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        
        self.isUserInteractionEnabled = false
        self.titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: SizeFitFloat(15), text: "扫描下方二维码")
        self.titleLabel?.numberOfLines = 0
        self.addSubview(self.titleLabel!)
        self.titleLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(41))
            make.right.equalTo(-SizeFitFloat(48))
            make.top.equalTo(SizeFit(22))
        }
        
        self.stepLabel =  LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: UIColor.white, fontSize: SizeFitFloat(16), text: "1", corner: SizeFitFloat(10))
        self.addSubview(self.stepLabel!)
        self.stepLabel?.backgroundColor = YellowColor
        self.stepLabel!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(13))
            make.height.width.height.equalTo(SizeFit(20))
            make.centerY.equalTo(self.titleLabel!)
        }
        
        self.checkImageView = LGTViewCreateUtil.share.createImageViewCorner(corner: SizeFitFloat(5))
        self.checkImageView?.backgroundColor = YellowColor
        self.addSubview(self.checkImageView!)
        self.checkImageView!.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFitFloat(42))
            make.height.equalTo(SizeFitFloat(165))
            make.width.equalTo(SizeFitFloat(128))
            make.top.equalTo(self.titleLabel!.snp_bottomMargin).offset(SizeFit(12))
        }
        
        self.descLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.center, textColor: UIColor.white, fontSize: SizeFitFloat(12), text: "说明图")
        self.checkImageView!.addSubview(self.descLabel!)
        self.descLabel?.backgroundColor = BlackAlpha46
        self.descLabel!.snp.makeConstraints { (make) in
            make.left.right.bottom.equalTo(self.checkImageView!)
            make.height.equalTo(SizeFitFloat(28))
        }
        
        let imageLine:UIImageView = LGTViewCreateUtil.share.createLineView()
        self.addSubview(imageLine)
        imageLine.backgroundColor = ColorUtil(color: 0xEFEFEF)
        imageLine.snp.makeConstraints { (make) in
            make.left.equalTo(SizeFit(13))
            make.right.equalTo(-SizeFit(11))
            make.height.equalTo(1)
            make.top.equalTo(self.checkImageView!.snp_bottomMargin).offset(SizeFit(14))
            make.bottom.equalTo(0)
        }
    }
    
    func gotoActionBlock(index:Int){
        if self.stepCellClickBlock != nil{
            self.stepCellClickBlock!(self.model, self.path!, index)
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

